package com.zlx.guguanjia.controller;

import com.github.pagehelper.PageInfo;
import com.zlx.guguanjia.entity.Result;
import com.zlx.guguanjia.entity.SysArea;
import com.zlx.guguanjia.entity.SysUser;
import com.zlx.guguanjia.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * @Author 周罗校
 * @Description
 * @ClassName SysUserController
 * @date 2020.11.03 17:40:35
 * 该版权归周罗校所有，最终解释权以官方为准
 */
@RestController
@RequestMapping("/manager/user")
public class SysUserController {

    @Autowired
    private SysUserService service;
    @GetMapping("selectPage/{start}/{pageSize}")
    public Result selectPage(@PathVariable("start") int start, @PathVariable("pageSize") int pageSize, @RequestParam Map<String, Object> condition) {
        PageInfo<SysArea> sysAreaPageInfo = service.selectPage(start, pageSize, condition);
        return new Result(sysAreaPageInfo);
    }

    @PutMapping("updateInfoById")
    public Result updateInfoById(@RequestBody SysUser user) {
        user.setUpdateDate(new Date());
        return new Result(service.updateByPrimaryKeySelective(user));
    }

    //逻辑删除
    @PutMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id) {
        SysUser user = new SysUser();
        user.setId(id);
        //标记删除了
        user.setDelFlag("1");
        user.setUpdateDate(new Date());
        return new Result(service.updateByPrimaryKeySelective(user));
    }


    @GetMapping("selectUserById/{rid}")
    public Result selectUserById(@PathVariable("rid") Long rid){
        return new Result(service.selectByRid(rid));
    }

    @GetMapping("selectNotSelectRoleUser/{rid}/{oid}")
    public Result selectNotSelectRoleUser(@PathVariable("rid") Long rid,@PathVariable("oid") Long oid){
        return new Result(service.selectNotSelectRoleUser(rid,oid));
    }
    @GetMapping("selectOne/{id}")
    public Result selectOne(@PathVariable("id") Long id){
        SysUser user = new SysUser();
        user.setId(id);
        return new Result(service.selectOne(user));
    }

}
